import sys
sys.path.append("C:\\vs2010 workspace\\Projects\\Lib\\Lib\\Agente\\Framework")

from _agents import MiniMaxAgent, AlphaBetaAgent
from Kosong import Game
from Kosong import Kosong


class MiniMaxObligatorio(AlphaBetaAgent):
    def __init__(self, name="AlphaBetaAgent", horizon=3, random=None, heuristic=None, params={}):
        self.params = params
        AlphaBetaAgent.__init__(self, name, horizon, random, heuristic)
    
    def valorPieza(pieza, Mayus):
        if pieza == 'a':
            if (Mayus):
                return -0.5
            else:
                return 0.5
        elif pieza == 'b':
            if (Mayus):
                return -0.01
            else:
                return 0.01
        elif pieza == 'c':
            if (Mayus):
                return -0.03
            else:
                return 0.03
        elif pieza == 'A':
            if (Mayus):
                return 0.5
            else:
                return -0.5
        elif pieza == 'B':
            if (Mayus):
                return 0.01
            else:
                return -0.01
        elif pieza == 'C':
            if (Mayus):
                return 0.03
            else:
                return -0.03
        elif (pieza == '0'):
            return 0

    def __heuristic__(self, game, depth):
        Mayus = self.player == 'Mayus'
        score = 0
        tablero = game.board
        for i in range(len(tablero)):
            letra = tablero[i]
            if (self.params == {}):
                score+= valorPieza(letra, Mayus)    
            else:
                if (letra == '0'):
                    score += self.params[letra];
                else:
                    if (Mayus):
                        if (letra.isupper()):
                            score += self.params[letra]
                        else:
                            score -= self.params[letra]
                    else:
                        if (letra.isupper()):
                            score -= self.params[letra]
                        else:
                            score += self.params[letra]
        
        max = self.params['A']*2 + self.params['B']*6 + self.params['C']*2
        score = score / max
        if ((score > 2) or (score < -2)):
            print('Score fuera de rango!!!!!!')
        return score
